<?php
	include_once "xAP-functions/webincludes.php";
$id=intval($_GET["id"]);
$item=array();



$results=dbquery("SELECT * FROM xap_iphone_item where screenid=".$id);
//build all Divs.  no data as such just positions
foreach($results as $v){
	if($v["Background"]!=""){
		$item[]="<div id='dev".$v["ItemID"]."' style=\"text-align:".$v["Align"].";position: absolute; top: ".$v["Y"]."px; left: ".$v["X"]."px; width: ".$v["Width"]."px; height: ".$v["Height"]."px;background-color: ".$v["Background"].";\" OnClick=\"Run('dev".$v["ItemID"]."')\"/>";
		}else{
		$item[]="<div id='dev".$v["ItemID"]."' style=\"text-align:".$v["Align"].";position: absolute; top: ".$v["Y"]."px; left: ".$v["X"]."px; width: ".$v["Width"]."px; height: ".$v["Height"]."px;background-color: transparent;border: none;\" OnClick=\"Run('dev".$v["ItemID"]."')\"/>";
		}
}

//exaample line
//<div id='dev1' style="text-align:center;position: absolute; top: 0px; left: 50px; width: 120px; height: 150px;background-color: transparent;border: none;"/>



$q="?";
header("Content-type: text/xml");
?>
<<?=$q?>xml version="1.0" encoding="UTF-8"?>
<root>
<title set="waLayer1">Test</title>
<part>
<destination mode="replace" zone="waLayer1"  create="true"/>
<data><![CDATA[
<div id='PageBase'>
<? foreach($item as $v):?>
<?=$v?>
<? endforeach;?>

</div>
<script>
	clearTimeout ( PageTimer );
	PageTimer=setInterval("LoadRefresh()",1000);
	var PageTime=0;
	function LoadRefresh(){
		$.get("/Floorplan/iphone_data.php?id=<?=$id?>&time=" + PageTime,function(data){
			items=data.split('~~~');
			PageTime=items[0];
			for (i=1;i<items.length;i++){
				item=items[i].split('###');
				$('#dev' + item[0]).html(item[1]);
			}
		});
	}
	function Run(dev){
		$('#' + dev).html("");
		$.get("/Floorplan/iphone_control.php?id=<?=$id?>&dev=" + dev,function(data){
			
		});
		
	}
</script>
]]></data>
</part>
</root>